using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Domain.Effectivity
{
    /// <summary>
    /// Base class for unittests that require a modified the application time.
    /// </summary>
    public class TemporalUnitTest
    {
        public const string InitialTemporalValue = "2000-01";
        private ApplicationEnvironment original;

        /// <summary>
        /// Load the modified application environment.
        /// </summary>
        [TestInitialize]
        public void TestInitialize()
        {
            this.original = ApplicationEnvironment.Instance;
            ApplicationEnvironment.Instance = new ApplicationEnvironment(DateTime.UtcNow, new DateTime(1998, 01, 01));
        }

        /// <summary>
        /// Restore the original application environment.
        /// </summary>
        [TestCleanup]
        public void TestCleanUp()
        {
            ApplicationEnvironment.Instance = this.original;
        }

        /// <summary>
        /// Creates a temporal object with one effectivity that starts on 2000-01-01 with value "2000-01"
        /// </summary>
        /// <returns></returns>
        public static ITemporal<string> Create()
        {
            Temporal<string> temporal = new Temporal<string>();
            temporal.Modify(InitialTemporalValue, new DateTime(2000, 1, 1));
            return temporal;
        }
    }
}